package com.suixinsanren.design.observer.demo04;

import java.util.Date;

public class AverageDisplay implements Observer, DisplayWeatherDate {

    private double maxTemperature;
    private double minTemperature;
    private double currentTemperature;
    private double humidity;
    private Date date;

    @Override
    public void display() {
        double averageTemperature = (maxTemperature + minTemperature) / 2;
        System.out.println("今天是" + date.toString() + "，平均温度：" + averageTemperature);
    }

    @Override
    public void update(Date date, double maxTemperature, double minTemperature, double currentTemperature, double humidity) {
        this.maxTemperature = maxTemperature;
        this.minTemperature = minTemperature;
        this.currentTemperature = currentTemperature;
        this.humidity = humidity;
        this.date = date;
        display();
    }
}
